import { RequestApi } from '@/net/common/API';
import Const from '@/utils/Const';
import request from '@/utils/request';
import axios from 'axios';

// 机构列表-机构树
export async function getByScope(params?: any) {
  return request(`/bf/common/org/get_org_tree`, {
    method: 'get',
    params,
  });
}

// 人员模块接口

// 人员列表
export async function ucEmployeePage(params: any) {
  let data = Const.dealParamsSwitch(params);
  const apiObj = {
    url: '/bf/uc/employee/page',
    method: 'post',
    data,
  };
  return new RequestApi().getRequest(apiObj);
}

// 通过ID查询系统人员记录
export async function ucEmployeeGetId(id: string) {
  return request(`/bf/uc/employee/get/${id}`, {
    method: 'get',
  });
}

// 加载管理员管理范围的人员，返回UserEmployeeVO结构的数据集
export async function ucEmployeeGetByMgtorg(data: any) {
  return request(`/bf/uc/employee/get_by_mgtorg`, {
    method: 'post',
    data,
  });
}

// 通过ID删除系统人员记录
export async function ucEmployeeDeleteId(id: string) {
  return request(`/bf/uc/employee/delete/${id}`, {
    method: 'post',
  });
}

// 批量修改人员归属机构
export async function ucEmployeeBatchChgOrg(data: any) {
  return request('/bf/uc/employee/batch_chg_org', {
    method: 'post',
    data,
  });
}

// 新增人员信息保存
class NewRequestApi extends RequestApi {
  getContentType() {
    return '';
  }
}
export async function ucEmployeeSave(data: any) {
  const apiObj = {
    url: '/bf/uc/employee/save',
    method: 'post',
    requestType: 'form',
    data,
  };
  return new NewRequestApi().getRequest(apiObj);
}

// 修改系统人员信息保存
export async function ucEmployeeUpdate(data: any) {
  const apiObj = {
    url: '/bf/uc/employee/update',
    method: 'post',
    requestType: 'form',
    data,
  };
  return new NewRequestApi().getRequest(apiObj);
}

// 组织结构模块接口、

// 批量授权
export async function ucOrganizationBatchUpdateAuthorization(data: any) {
  return request('/bf/uc/organization/batch_update_authorization', {
    method: 'post',
    data,
  });
}

// 通过ID删除组织机构，包括根、公司、部门等等记录
export async function ucOrganizationDeleteId(id: string) {
  return request(`/bf/uc/organization/delete/${id}`, {
    method: 'post',
  });
}

// 通过ID查询组织机构，包括根、公司、部门等等记录
export async function ucOrganizationGetId(id: string) {
  return request(`/bf/uc/organization/get/${id}`, {
    method: 'get',
  });
}

// 分页
export async function ucOrganizationPage(params: any) {
  let data = Const.dealParamsSwitch(params);
  const apiObj = {
    url: '/bf/uc/organization/page',
    method: 'post',
    data,
  };
  return new RequestApi().getRequest(apiObj);
}

// 下载文件
export async function fileAttachmentDownload(params: any) {
  return request('/bf/uc/fat/download', {
    method: 'get',
    params,
    responseType: 'blob',
    //
  });
}

//注意 这里获取图片 需要使用axios
//使用上面的fileAttachmentDownload umi-request的有问题 请求二进制blob的会返回空值null
//具体原因待分析
export const fileAttachmentDownloadForAxios = async (params: any) => {
  return await axios.get(`/bf/uc/fat/download`, {
    params: params,
    responseType: 'blob',
  });
};

// 新建组织机构，包括根、公司、部门等等记录
export async function ucOrganizationSave(data: any) {
  return request('/bf/uc/organization/save', {
    method: 'post',
    data,
  });
}

// 修改组织机构，包括根、公司、部门等等记录
export async function ucOrganizationUpdate(data: any) {
  return request('/bf/uc/organization/update', {
    method: 'post',
    data,
  });
}

// 资源模块

// 获取所有子系统
export async function sysResGetSubsystem() {
  return request('/bf/sys/res/get/subsystem', {
    method: 'get',
  });
}

// 获取子系统下的资源
export async function sysResTree(data: any) {
  return request('/bf/sys/res/tree', {
    method: 'post',
    data,
  });
}

// 根据指定范围加载菜单资源树
export async function commonMenuGetByScope(data?: any) {
  return request('/bf/common/menu/get_by_scope', {
    method: 'post',
    data,
  });
}
